# Estimate emotional changes by treatment and partisanship
# See Appendix E




#############
# load data #
#############

library(dplyr)
library(stargazer)

load("PSRM Replication Files/SurveyResponses.Rdata") # data, 2008, 44
colnames(data)

# check
sum(data$dem) # 1000
sum(data$pop) # 1029




########################################
# average emotions and post-pre change #
########################################

# emotions
positive <- "interested|inspired|enthusiastic|proud|excited"
negative <- "upset|scared|ashamed|nervous|hostile"

# pre-treatment affect scores
data$pre_pa <- data %>% select(matches("_pre")) %>% select(matches(positive)) %>% 
  mutate(across(, as.numeric)) %>% rowSums()
data$pre_na <- data %>% select(matches("_pre")) %>% select(matches(negative)) %>% 
  mutate(across(, as.numeric)) %>% rowSums()

# post-treatment affect scores
data$post_pa <- data %>% select(matches("_post")) %>% select(matches(positive)) %>% 
  mutate(across(, as.numeric)) %>% rowSums()
data$post_na <- data %>% select(matches("_post")) %>% select(matches(negative)) %>% 
  mutate(across(, as.numeric)) %>% rowSums()

# post-pre difference in affect
data <- data %>% 
  mutate(diff_pa = post_pa - pre_pa, 
         diff_na = post_na - pre_na)

# check
dim(data) # 2008 50

# run ols
mod_PA <- lm(diff_pa ~ as.factor(dem)*as.factor(pop), data=data)
mod_NA <- lm(diff_na ~ as.factor(dem)*as.factor(pop), data=data)

# table E.1
stargazer(mod_PA, mod_NA, model.names = F,
          dep.var.labels = c("$\\Delta$ Positive emotion", "$\\Delta$ Negative emotion"),
          intercept.top = T, intercept.bottom = F,
          covariate.labels = c("Change for Republicans", "Democrat Indicator", "Populism", "Democrat $\\times$ Populism"),
          keep.stat = c("n", "adj.rsq"))
